// pages/in/in.js
var app =getApp()

Page({

  /**
   * 页面的初始数据
   */
  data: {

    name: '',
    content: '',
    phone: '',
    ID:'',
    modalName: '',
    value: "",
    region: ['广东省', '广州市', '海珠区'],
    customItem: '全部',
    addressArr: [],
    dizhivalue: '',
    xingbie:1,
    text: "请您的积极配合防疫要求，共同抗击疫情",
    marqueePace: 0.5, //滚动速度
    marqueeDistance: 2, //初始滚动距离
    marquee_margin: 50,
    size: 14,
    interval: 40, // 时间间隔
  },

  
  scrolltxt: function () {
    var that = this;
    var length = that.data.length; //滚动文字的宽度
    var windowWidth = that.data.windowWidth; //屏幕宽度
    if (length > windowWidth) {

      var interval = setInterval(function () {
        var maxscrollwidth = length + that.data.marquee_margin; //滚动的最大宽度，文字宽度+间距，如果需要一行文字滚完后再显示第二行可以修改marquee_margin值等于windowWidth即可
        var crentleft = that.data.marqueeDistance;
        if (crentleft < maxscrollwidth) { //判断是否滚动到最大宽度
          
          that.setData({
            marqueeDistance: crentleft + that.data.marqueePace
          })
        } else {
        
          that.setData({
            marqueeDistance: 0 // 直接重新滚动
          });
          clearInterval(interval);
          that.scrolltxt();
        }
      }, that.data.interval);
    } else {
      that.setData({
        marquee_margin: "1000"
      }); //只显示一条不滚动右边间距加大，防止重复显示
    }
  },
  onLoad(e){
    wx.setNavigationBarTitle({
      title: '核酸人口登记'
    })

    
  },
  onShow(){
    var that = this;
    var length = that.data.text.length * that.data.size; //文字长度
    var windowWidth = wx.getSystemInfoSync().windowWidth; // 屏幕宽度
    //console.log(length,windowWidth);
    that.setData({
      length: length,
      windowWidth: windowWidth
    });
    that.scrolltxt(); // 第一个字消失后立即从右边出现
  },
  changes(e) {
    this.setData({
      value: e.detail.value
    })
  },
  change(e) {
    if (this.data.modalName == '姓名') {
      this.setData({
        name: this.data.value,
        value: ''
      })
    } else if(this.data.modalName == "身份证"){
      this.setData({
        ID: this.data.value,
        value: ''
      })
    }else if(this.data.modalName == "电话号"){
      this.setData({
        phone: this.data.value,
        value: ''
      })
    }
    this.setData({
      modalName: ''
    })
  },
  onTap(e) {
    console.log(e.currentTarget.dataset.id)
    this.setData({
      modalName: e.currentTarget.dataset.id
    })
  },
  in () {
    wx.chooseMessageFile({
      count: 10,
      success: (res) => {
        console.log(res.tempFiles)

      }
    })
  },
  

  hideModal() {
    this.setData({
      modalName: ''
    })
  },
  setMessage(e) {
    this.setData({
      content: e.detail.value
    })
  },

  sexTap(e){
    if(this.data.xingbie == 1){
      this.setData({
        xingbie:0
      })
    }else{
      this.setData({
        xingbie:1
      })
    }
  },

    /**
   * 页面的初始数据
   */
 

 
  RegionChange: function (e) {
    console.log(e)
    this.data.region = e.detail.value
    this.setData({
      region: this.data.region
    })
  },

  // 提交新地址
  submit: async function (e) {
    
    console.log('form发生了submit事件，携带数据为：', e.detail.value)
    let address = await this.zu()
    console.log(address)
  },
  zu(){
    let that = this
    return new Promise((resolve , reject )=>{
      resolve(that.data.region.join(""))
    })
  }
})